<template>
  <div class="login-container">
    <div class="one">
      <input type="text" id="tip"  @keyup.enter="login" v-model="userName" placeholder="" />
      <i class="icon"></i>
    </div>
    <div class="two">
      <input id="tip" placeholder=""  @keyup.enter="login" v-model="password" type="password">
      <i class="icon"></i>
    </div>
    <div class="btn" @click=login>
      登录
    </div>
  </div>
</template>

<script>
import { login, getUserSid } from '@/api/user'
import { rsaDecrypt } from '@/utils/commonutils3'
// import { setSid, getToken, getSid } from '@/utils/auth'
import { setSid, removeToken, removeSid } from '@/utils/auth'
import md5 from 'md5'
export default {
  name: 'Login',
  data() {
    return {
      userName: '',
      password: '',
      sid: '',
      loading: false,
      passwordType: 'password'
    }
  },
  watch: {

  },
  created() {

  },
  methods: {
    async login() {
      if (!this.userName || !this.password) {
        return this.$message.error('账号密码不能为空')
      }
      const res = await login({ userName: this.userName, password: md5(this.password) })
      if (res.code === 200) {
        console.log(rsaDecrypt(res.data.data), 'res')
        const data = rsaDecrypt(res.data.data)
        // return
        this.$store.dispatch('user/login', data.token).then(() => {
          // this.$router.push({ path: this.redirect || '/' })
          // this.loading = false
          // this.getUserId(data.sid)
          this.sid = data.sid
          setSid(this.sid)
          this.$router.push('/index')
        }).catch(() => {
          this.loading = false
        })
        // }
      } else {
        console.log('1111');
        return this.$message.error(res.message)
      }
    },

  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg: #283443;
$light_gray: #fff;
$cursor: #fff;

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  background: url(../../assets/img/loginBGc.png) no-repeat center 0px;
  background-size: contain;

  .inputClass {
    margin-top: 1.3542rem;
    margin-left: 3.125rem;
    width: 3.7552rem;
    height: .3333rem;
    border-radius: .1667rem;
    background-color: #001743;
    border: 1px solid #0075FF;

  }

  .inputClass:focus {
    border: 1px solid #0075FF;
  }

  .one {
    color: #434343;
    position: relative;
    width: 3.7552rem;
    height: .3333rem;
    margin-top: 1.25rem;
    margin-left: 3.125rem;
    margin-bottom: .2604rem;
    background-color: #001743;
    border: 1px solid #0075FF;
    border-radius: .1667rem;

    input {
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      outline: 0;
      width: 100%;
      height: 100%;
      background-color: #001743;
      border: 0px solid #fff;
      border-radius: .1667rem;
      box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.1);
      padding: 0 .1563rem 0 .3646rem;
      color: #fff;

    }

    label {
      font-size: .1667rem;
      z-index: 2;
      position: absolute;
      left: .5208rem;
      top: 15%;
      color: #fff;
    }

    .icon {
      display: inline-block;
      height: .1667rem;
      width: .1667rem;
      background-image: url(../../assets/img/zhanghao.svg);
      /*这里放置图标的绝对路径*/
      background-repeat: no-repeat;
      background-size: contain;
      position: absolute;
      top: .0521rem;
      left: .1042rem;
      z-index: 2;
    }
  }

  .two {
    color: #434343;
    position: relative;
    width: 3.7552rem;
    height: .3333rem;
    // margin-top: 1.3542rem;
    margin-bottom: .2604rem;
    margin-left: 3.125rem;
    background-color: #001743;
    border: 1px solid #0075FF;
    border-radius: .1667rem;

    input {
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      outline: 0;
      width: 100%;
      height: 100%;
      background-color: #001743;
      border: 0px solid #fff;
      border-radius: .1667rem;
      box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.1);
      padding: 0 .1563rem 0 .3646rem;
      color: #fff;

    }

    label {
      font-size: .1667rem;
      z-index: 2;
      position: absolute;
      left: .5208rem;
      top: 15%;
      color: #fff;
    }

    .icon {
      display: inline-block;
      height: .1667rem;
      width: .1667rem;
      background-image: url(../../assets/img/password.svg);
      /*这里放置图标的绝对路径*/
      background-repeat: no-repeat;
      background-size: contain;
      position: absolute;
      top: .0521rem;
      left: .1042rem;
      z-index: 2;
    }
  }

  .btn {
    width: .7813rem;
    height: .3333rem;
    line-height: .3333rem;
    margin: 0 auto;
    background-color: #001743;
    border: 1px solid #0075FF;
    border-radius: .1667rem;
    color: #fff;
    font-size: .125rem;
    text-align: center;
    cursor: pointer;
  }

}
</style>

<style lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;

.login-container {
  min-height: 100%;
  width: 100%;
  background-color: $bg;
  overflow: hidden;
}
</style>
